#include <bits/stdc++.h>
#define ll long long
#define maxn 100010
#define maxm 1000010
using namespace std;
#define writesp(X) write((X)), putchar(' ')
#define writeln(X) write((X)), putchar('\n')
#define lson(X) ((X) << 1)
#define rson(X) (((X) << 1) | 1)
template < typename T >
inline void read(T &X)
{
    X = 0; bool f = false; char ch = getchar();
    while (!isdigit(ch)) {f |= ch == '-'; ch = getchar();}
    while (isdigit(ch)) {X = (X * 10) + (ch ^ 48); ch = getchar();}
    X = f ? -X : X;
    return;
}
template < typename T >
inline void write(T X)
{
    if (X == 0) {putchar('0'); return;}
    if (X < 0) {putchar('-'); X = -X;}
    static char ch[20], cnt = 0;
    while (X) {*(ch + cnt++) = X % 10; X /= 10;}
    while (cnt) putchar(*(ch + --cnt) ^ 48);
    return;
}
struct line
{
    int l, r;
    line (const int &_l = 0, const int &_r = 0) : l(_l), r(_r) {}
    bool operator < (const line &b) const {return this->l == b.l ? this->r > b.r : this->l < b.l;}
};
priority_queue < line > q;
set < int > s1, s2;
int T;
int n, m;
ll Lm, vm;
int lcnt;
int main()
{
    // ll start = chrono::system_clock().now().time_since_epoch().count();
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    read(T);
    while (T--)
    {
        read(n); read(m); read(Lm); read(vm);
        s1.clear(); s2.clear(); lcnt = 0;
        for (int i = 1; i <= n; ++i)
        {
            ll d, v, a;
            read(d); read(v); read(a);
            if (v <= vm && a <= 0) continue;
            if (v > vm && a >= 0) {q.emplace(d, Lm); continue;}
            if (v <= vm && a > 0)
            {
                ll l = d + (vm * vm - v * v) / 2 / a + 1;
                if (l <= Lm) q.emplace(l, Lm);
            }
            else
            {
                ll r = d + (max(0ll, v * v - vm * vm - 1)) / 2 / -a;
                q.emplace(d, min(r, Lm));
            }
        }
        for (int i = 1; i <= m; ++i) {int a; read(a); s1.insert(a);}
        while (!q.empty())
        {
            int l = q.top().l, r = q.top().r; q.pop();
            set < int > ::iterator it1 = s1.lower_bound(l);
            if (it1 == s1.end() || *it1 > r) continue;
            ++lcnt;
            set < int > ::iterator it2 = s2.lower_bound(l);
            if (it2 == s2.end() || *it2 > r) s2.insert(*it1);
        }
        writesp(lcnt); writeln(m - s2.size());
    }
    // ll end = chrono::system_clock().now().time_since_epoch().count();
    // cerr << (end - start) / 60.0 / 60 / 60 / 60 / 60 << endl;
    return 0;
}